
var Main = require("Main");
cc.Class({
    extends: cc.Component,

    properties: {

    },



    start() {
        this.mousePos0 = null;//初始位置
        this.out = false;//用于判断物体是否移除
        this.isDrag = false;//判断物体是否是拖拽状态
        this.only = true;//拖拽过程中 只判断一次物体状态
        this.puzzleBG = [];//拼图背景组成的数组
        this.disArray = [];//移出后松手时，每个背景距离物体的距离组成的数组
        this.disArrayFriend = [];
        this.startpos = [];//所有物体的初始位置组成的数组
        this.main = cc.find("Canvas").getComponent(Main);

        this.isHave = this.main.isHave;//关联脚本
        this.startpuzzle = this.main.startpuzzle;
        this.BGisHave = this.main.BGisHave;
        this.index = 1;//索引，用于判断松手后，物体的位置
        this.indexFriend = 1;
        this.minIndex = 0;
        this.minIndexFriend = 0;
        this.once = true;
        this.haveBig = false;
        this.isfind = false;
        this.letgo = true;
        this.width = this.main.colum;
        this.height = this.main.row;
        // this.useless = this.main.useless;
        this.name = this.node.getChildByName("New Label").getComponent(cc.Label).string;
        this.BGW = 0;
        this.BGH = 0;
        this.BGWFriend = 0;
        this.BGHFriend = 0;
        this.distance = 0;
        this.poschangedelaytime = 0;
        this.AllCorrectArray = this.main.AllCorrectArray;
        this.LockArray = this.main.LockArray;
        this.isLock = this.main.isLock;
        //   console.log(this.isLock);
        this.puzzleBG2 = this.main.puzzleBG2;
        this.correctMusic = this.main.puzzleBGNode.getComponent(cc.AudioSource);
        this.moveMusic = this.main.movePart.getComponent(cc.AudioSource);

        this.totalCount = this.main.row * this.main.colum + this.main.useless;
        //this.mask = this.main.mask;
        // this.repeatLabel = this.main.repeatLabel;
        // this.repeatButton = this.main.repeatButton;
        // this.winLabel = this.main.winLabel;

        //this.currentzIndex = this.node.zIndex + 1;


        // console.log(this.correctMusic);

        // this.LockArray.push(1);
        // console.log(this.main.LockArray);
        var self = this;
        var puzzlebgChildren = this.main.puzzleBGNode.getChildren();
        for (let i = 0; i < puzzlebgChildren.length; i++) {
            this.puzzleBG.push(puzzlebgChildren[i]);

        }
        // console.log(this.puzzleBG);
        for (let i = 0; i < this.totalCount; i++) {
            self.startpos.push(cc.p(-1643 + 200 * i, -100));
        }



        this.node.on(cc.Node.EventType.TOUCH_START, function (event) {
            self.mousePos0 = event.getLocation();
            var find2 = false;
            for (let i = 0; i < self.AllCorrectArray.length; i++) {
                if (self.AllCorrectArray[i].indexOf(this) != -1) {
                    for (let j = 0; j < self.AllCorrectArray[i].length; j++) {
                        self.AllCorrectArray[i][j].setSiblingIndex(this.totalCount);
                    }
                    find2 = true;
                    break;
                }
            }

            if (!find2) {

                this.setSiblingIndex(this.totalCount);


            }
        }, this.node);
        this.node.on(cc.Node.EventType.TOUCH_MOVE, function (event) {
            if (self.out) {
                self.main.scrollView.getComponent(cc.ScrollView).enabled = false;
                var delta = event.touch.getDelta();
                self.only = false;
                this.opacity = 255;
                this.x += delta.x;
                this.y += delta.y;
            } else {
                var delta = event.touch.getDelta();

                if (self.only) {

                    if (Math.abs(delta.y / delta.x) < 2) {
                        // self.isDrag = false;
                    }
                    else {
                        self.isDrag = true;
                        //this.position = cc.find("Canvas/MovePart").convertToNodeSpaceAR(event.getLocation());
                    }
                }
                if (self.isDrag == true) {
                    self.main.scrollView.getComponent(cc.ScrollView).enabled = false;

                    self.only = false;
                    this.opacity = 255;
                    this.x += delta.x;
                    this.y += delta.y;
                }
                else {
                    self.only = false;
                    //  self.isSlide = true;
                    this.x += 0;
                    this.y += 0;
                }
            }
            // console.log(self.isDrag);
            if (self.isDrag == true) {
                //拖拽前后，下面方块的变化(不松手)

                if (self.AllCorrectArray.length > 0) {


                    //遍历连接正确的数组，找到点击物体所在的数组
                    for (let i = 0; i < self.AllCorrectArray.length; i++) {
                        for (let j = 0; j < self.AllCorrectArray[i].length; j++) {
                            if (self.AllCorrectArray[i].indexOf(this) != -1 && j != self.AllCorrectArray[i].indexOf(this)) {
                                self.AllCorrectArray[i][j].x += delta.x;
                                self.AllCorrectArray[i][j].y += delta.y;

                            }
                        }

                    }

                }



                // console.log(self.AllCorrectArray);
                if (this.y >= 80) {


                    if (self.once == false) {
                        return;
                    }
                    self.once = false;
                    this.parent = self.main.movePart;
                    console.log(this.parent);
                    console.log(self.main.content);
                    this.position = cc.v2(this.position.x + self.main.content.position.x, this.position.y);
                    console.log(self.startpuzzle);
                    for (let i = self.startpuzzle.indexOf(this) + 1; i < self.startpuzzle.length; i++) {
                        self.startpuzzle[i].stopAllActions();
                        var action = cc.moveTo(0.15, self.startpos[i - 1]);
                        console.log("原始位置" + this.position);
                        self.startpuzzle[i].runAction(action);
                        console.log("向前一步走");
                        console.log("结束位置" + self.startpos[i - 1]);
                    }

                    self.isHave[self.startpuzzle.indexOf(this)] = true;
                    self.isHave[self.startpuzzle.length - 1] = false;
                    self.startpuzzle.splice(self.startpuzzle.indexOf(this), 1);

                    console.log(self.isHave);
                    console.log(self.startpuzzle);
                    console.log("删一个");

                }
                else if (this.y < 80) {
                    for (let i = 0; i < self.AllCorrectArray.length; i++) {
                        for (let j = 0; j < self.AllCorrectArray[i].length; j++) {
                            if (self.AllCorrectArray[i].indexOf(this) != -1) {
                                return;
                            }
                        }
                    }

                    // if (self.once == true) {
                    //     return;
                    // }
                    // self.once = true;
                    var pos = this.parent.convertToWorldSpaceAR(this.position);
                    // console.log(pos);
                    if (self.once == false) {

                        self.once = true;
                        this.parent = self.main.content;

                        this.position = cc.v2(this.position.x - self.main.content.position.x, this.position.y);

                        for (let i = 0; i < self.startpuzzle.length; i++) {

                            if (self.startpuzzle[i].parent.convertToWorldSpaceAR(self.startpuzzle[i].position).x > pos.x) {

                                self.haveBig = true;
                                for (let j = i; j < self.startpuzzle.length; j++) {
                                    // self.startpuzzle[j].position = self.startpos[j + 1];
                                    self.startpuzzle[j].stopAllActions();
                                    var action = cc.moveTo(0.15, self.startpos[j + 1]);

                                    self.startpuzzle[j].runAction(action);

                                }

                                self.startpuzzle.splice(i, 0, this);

                                self.isHave[i] = false;
                                self.isHave[self.startpuzzle.length - 1] = true;
                                console.log(self.isHave);
                                console.log(self.startpuzzle);
                                break;
                            }

                        }


                        if (self.haveBig == false) {
                            self.startpuzzle.push(this);
                            console.log(self.isHave);
                            console.log(self.startpuzzle);
                        }


                    }
                    else {
                        this.parent = self.main.content;

                        // this.position = cc.v2(this.position.x - cc.find("Canvas/PuzzleChooseScrollView/view/content").position.x, this.position.y);

                        if (self.startpuzzle.indexOf(this) != -1) {
                            self.isHave[self.startpuzzle.indexOf(this)] = false;
                        }

                        for (let i = 0; i < self.startpuzzle.length; i++) {
                            if (i == self.startpuzzle.indexOf(this)) {
                                continue;
                            }

                            if (Math.abs(pos.x - self.startpuzzle[i].parent.convertToWorldSpaceAR(self.startpuzzle[i].position).x) <= 10) {

                                for (let j = 0; j < self.isHave.length; j++) {
                                    if (self.isHave[j] == false) {
                                        self.startpuzzle[i].position = self.startpos[j];
                                        var bottle = null;

                                        self.isHave[self.startpuzzle.indexOf(this)] = true;
                                        self.isHave[self.startpuzzle.indexOf(self.startpuzzle[i])] = false;
                                        bottle = self.startpuzzle[self.startpuzzle.indexOf(this)];
                                        self.startpuzzle[self.startpuzzle.indexOf(this)] = self.startpuzzle[i];
                                        self.startpuzzle[i] = bottle;
                                        console.log(self.isHave);
                                        console.log(self.startpuzzle);
                                        break;
                                    }
                                }
                            }
                        }

                    }





                }
            }


        }, this.node);
        this.node.on(cc.Node.EventType.TOUCH_END, function (event) {



            var wssss = event.getLocation();

            var nodePos = self.main.puzzleBGNode.convertToNodeSpaceAR(wssss);

            console.log(nodePos);

            self.only = true;
            clearTimeout(self.poschangedelaytime);

            self.letgo = false;


            self.poschangedelaytime = setTimeout(() => {
                self.letgo = true;
            }, 160);

            if (Math.floor(self.mousePos0.x) == Math.floor(wssss.x) && Math.floor(self.mousePos0.y) == Math.floor(wssss.y)) {
                if (nodePos.x < -300 || nodePos.x > 300 || nodePos.y > 750 || nodePos.y < 150) {
                    console.log("rui了");
                    return;

                }
                if (this.parent == self.main.content) {
                    return;
                }

                this.rotation += 90;
                console.log("转");
                if (self.AllCorrectArray.length > 0) {

                    var index = -1;
                    //遍历连接正确的数组，找到点击物体所在的数组
                    for (let i = 0; i < self.AllCorrectArray.length; i++) {
                        for (let j = 0; j < self.AllCorrectArray[i].length; j++) {
                            if (this == self.AllCorrectArray[i][j]) {
                                index = i;
                                break;
                            }
                        }
                        if (index != -1) {
                            break;
                        }
                    }
                    if (index != -1) {
                        //找到以后，
                        for (let i = 0; i < self.AllCorrectArray[index].length; i++) {
                            if (i == self.AllCorrectArray[index].indexOf(this)) {
                                continue;
                            }

                            self.distance = Math.sqrt((this.x - self.AllCorrectArray[index][i].x) * (this.x - self.AllCorrectArray[index][i].x) + (this.y - self.AllCorrectArray[index][i].y) * (this.y - self.AllCorrectArray[index][i].y))
                            if (self.AllCorrectArray[index][i].x >= this.x) {
                                self.AllCorrectArray[index][i].position = cc.p(Math.cos(Math.asin((self.AllCorrectArray[index][i].y - this.y) / self.distance) - Math.PI / 2) * self.distance + this.x, Math.sin(Math.asin((self.AllCorrectArray[index][i].y - this.y) / self.distance) - Math.PI / 2) * self.distance + this.y);
                            }
                            else {
                                self.AllCorrectArray[index][i].position = cc.p(Math.cos(- Math.asin((self.AllCorrectArray[index][i].y - this.y) / self.distance) + Math.PI / 2) * self.distance + this.x, Math.sin(-Math.asin((self.AllCorrectArray[index][i].y - this.y) / self.distance) + Math.PI / 2) * self.distance + this.y);
                            }

                            self.AllCorrectArray[index][i].rotation += 90;
                            if (self.main.mask.active == false) {
                                self.main.mask.active = true;

                            }
                            setTimeout(() => {
                                self.main.mask.active = false;
                            }, 300);
                            console.log(self.AllCorrectArray[index][i].position);
                        }
                    }




                }
            }



            self.main.scrollView.getComponent(cc.ScrollView).enabled = true;

            if (this.y >= 80) {

                self.up80(nodePos);



            }
            else if (this.y < 80) {
                var shoodreturn = false;
                for (let i = 0; i < self.AllCorrectArray.length; i++) {
                    for (let j = 0; j < self.AllCorrectArray[i].length; j++) {
                        if (self.AllCorrectArray[i].indexOf(this) != -1) {
                            shoodreturn = true;
                            self.up80(nodePos);
                            break;
                        }
                    }
                    if (shoodreturn) {
                        return;
                    }
                }

                self.out = false;



                for (let i = 0; i < self.isHave.length; i++) {
                    if (self.isHave[i] == false) {
                        console.log("动一动");
                        var action2 = cc.moveTo(0.1, self.startpos[i]);
                        this.runAction(action2);
                        self.isHave[i] = true;
                        console.log(self.isHave);
                        console.log(self.startpuzzle);
                        break;
                    }

                }

            }


        }, this.node);
        this.node.on(cc.Node.EventType.TOUCH_CANCEL, function (event) {


            self.only = true;


            self.main.scrollView.getComponent(cc.ScrollView).enabled = true;


        }, this.node);

        this.node.on('position-changed', function () {
            self.posChange();
        }, this.node);
    },

    onLoad() {

    },
    up80(nodePos) {
        var self = this;
        self.out = true;

        console.log("一上来进了吧");
        for (let i = 0; i < self.puzzleBG.length; i++) {
            var dis = Math.sqrt((nodePos.x - self.puzzleBG[i].x) * (nodePos.x - self.puzzleBG[i].x) + (nodePos.y - self.puzzleBG[i].y) * (nodePos.y - self.puzzleBG[i].y))
            self.disArray.push(dis);
        }
        console.log(self.disArray);
        var min = self.disArray[0];
        for (; self.index < self.disArray.length; self.index++) {
            if (self.disArray[self.index] <= min) {
                min = self.disArray[self.index];
                self.minIndex = self.index;
            }
        }
        console.log(self.puzzleBG);
        self.BGW = self.puzzleBG[self.minIndex].name[0];
        self.BGH = self.puzzleBG[self.minIndex].name[2];
        console.log(self.BGW + self.BGH);

        var finishedMain = cc.callFunc(function (target) {
            self.moveMusic.play();
            self.JudgeIsHave(self.BGW, self.BGH);
            setTimeout(() => {
                self.JudgeIsLock();
            }, 100);

            for (let i = 0; i < self.AllCorrectArray.length; i++) {
                if (self.AllCorrectArray[i].length == self.width * self.height && self.BGW == this.name[0] && self.BGH == this.name[2] && this.node.rotation % 360 == 0) {
                    self.main.mask.active = true;
                    self.main.repeatLabel.active = true;
                    self.main.repeatButton.active = true;
                    let action = cc.scaleTo(0.5, 1, 1);
                    self.main.winLabel.runAction(action);
                }
            }
        }, this)
        var actionMain = cc.moveTo(0.1, self.puzzleBG[self.minIndex]);
        var action2Main = cc.sequence(actionMain, finishedMain);
        console.log(self.BGisHave);
        this.node.runAction(action2Main);
        var isFinded = false;
        for (let i = 0; i < self.AllCorrectArray.length; i++) {
            for (let j = 0; j < self.AllCorrectArray[i].length; j++) {
                if (self.AllCorrectArray[i].indexOf(this.node) != -1) {
                    isFinded = true;
                    if (j == self.AllCorrectArray[i].indexOf(this.node)) {
                        continue;
                    }
                    let comparePos = cc.p((self.puzzleBG[self.minIndex].x) + (self.AllCorrectArray[i][j].x - this.node.x), (self.puzzleBG[self.minIndex].y) + (self.AllCorrectArray[i][j].y - this.node.y));
                    let action = cc.moveTo(0.1, comparePos);
                    let finished = cc.callFunc(function (target) {
                        console.log("回调了");
                        console.log("小兄弟们一起判断");
                        if (comparePos.x >= -300 && comparePos.x <= 300 && comparePos.y <= 750 && comparePos.y >= 150) {

                            for (let k = 0; k < self.puzzleBG.length; k++) {
                                var disFriend = Math.sqrt((comparePos.x - self.puzzleBG[k].x) * (comparePos.x - self.puzzleBG[k].x) + (comparePos.y - self.puzzleBG[k].y) * (comparePos.y - self.puzzleBG[k].y))
                                self.disArrayFriend.push(disFriend);
                            }
                            let min = self.disArrayFriend[0];
                            for (; self.indexFriend < self.disArrayFriend.length; self.indexFriend++) {
                                if (self.disArrayFriend[self.indexFriend] <= min) {
                                    min = self.disArrayFriend[self.indexFriend];
                                    self.minIndexFriend = self.indexFriend;
                                }
                            }

                            self.BGWFriend = self.puzzleBG[self.minIndexFriend].name[0];
                            self.BGHFriend = self.puzzleBG[self.minIndexFriend].name[2];
                            console.log(self.BGWFriend + self.BGHFriend);
                            console.log(self.AllCorrectArray);
                            console.log(i + ",," + j);
                            console.log(self.AllCorrectArray[i][j]);

                            if (self.AllCorrectArray[i][j] != undefined) {
                                let xsdd = self.AllCorrectArray[i][j].getComponent("Drag");
                                console.log(xsdd);
                                xsdd.JudgeIsHave(self.BGWFriend, self.BGHFriend);
                                setTimeout(() => {
                                    xsdd.JudgeIsLock();
                                }, 100);

                            }

                            console.log("小兄弟进了");


                        }

                        self.disArrayFriend.splice(0, self.puzzleBG.length);
                        self.indexFriend = 1;
                        self.minIndexFriend = 0;


                    }, this);
                    var action2 = cc.sequence(action, finished);
                    self.AllCorrectArray[i][j].runAction(action2);

                }
            }
            if (isFinded == true) {
                break;
            }
        }


        self.disArray.splice(0, self.puzzleBG.length);
        self.index = 1;
        self.minIndex = 0;

    },
    posChange() {
        var self = this;
        if (self.letgo) {
            for (let i = 0; i < self.BGisHave.length; i++) {
                for (let j = 0; j < self.BGisHave[i].length; j++) {
                    for (let k = 0; k < self.BGisHave[i][j].length; k++) {
                        if (this.node == self.BGisHave[i][j][k]) {
                            self.BGisHave[i][j].pop(this.node);
                            console.log("pop掉");
                            console.log(self.BGisHave);
                            self.isfind = true;
                            break;
                        }
                    }
                    if (self.isfind == true) {
                        break;
                    }
                }
                if (self.isfind == true) {
                    self.isfind = false;
                    break;
                }
            }
            //self.letgo = false;
        }
    },
    JudgeIsLock() {
        var self = this;
        //  if (this.node.rotation % 360 == 0) {
        for (let i = 0; i < self.BGisHave.length; i++) {
            for (let j = 0; j < self.BGisHave[i].length; j++) {
                if (self.BGisHave[i][j].length > 0) {
                    console.log("上面有东西");
                    for (let m = 0; m < self.BGisHave[i][j].length; m++) {
                        console.log(self.BGisHave[i][j][m].getComponent("Drag").name);
                        console.log(self.puzzleBG2[i][j].name);
                        if (self.BGisHave[i][j][m].getComponent("Drag").name == self.puzzleBG2[i][j].name && self.BGisHave[i][j][m].rotation % 360 == 0) {
                            console.log("相等了");
                            self.isLock[i][j] = true;
                            break;
                        }
                        else {
                            self.isLock[i][j] = false;
                        }
                    }
                }
                else {
                    self.isLock[i][j] = false;
                }

            }
        }
        // if (self.name == BGW + "_" + BGH) {
        //     self.isLock[BGW - 1][BGH - 1] = true;
        // }
        // else {
        //     self.isLock[BGW - 1][BGH - 1] = false;
        // }

        // }
        //  else {
        //     self.isLock[BGW - 1][BGH - 1] = false;
        // }

        var TopRowTrue = false;
        var BottomRowTrue = false;
        var LeftColumTrue = false;
        var RightColumTrue = false;
        for (var j = 0; j < self.isLock[0].length; j++) {
            if (self.isLock[0][j] == false) {
                BottomRowTrue = false;
                break;
            }
            else {
                BottomRowTrue = true;
            }
        }
        for (var j = 0; j < self.isLock[self.isLock.length - 1].length; j++) {
            if (self.isLock[self.isLock.length - 1][j] == false) {
                TopRowTrue = false;
                break;
            }
            else {
                TopRowTrue = true;
            }
        }
        for (var i = 0; i < self.isLock.length; i++) {
            //  for (var j = 0; j < self.isLock[i].length; j++) {
            if (self.isLock[i][0] == false) {
                LeftColumTrue = false;
                break;
            }
            else {
                LeftColumTrue = true;
            }
            //   }
        }
        for (var i = 0; i < self.isLock.length; i++) {
            // for (var j = 0; j < self.isLock[i].length; j++) {
            if (self.isLock[i][self.isLock[i].length - 1] == false) {
                RightColumTrue = false;
                break;
            }
            else {
                RightColumTrue = true;
            }
            // }
        }

        if ((TopRowTrue || BottomRowTrue) && (LeftColumTrue || RightColumTrue)) {
            for (let i = 0; i < self.AllCorrectArray.length; i++) {
                console.log(self.AllCorrectArray);
                console.log(self.main.AllCorrectArray);
                console.log(self.AllCorrectArray[i].indexOf(this.node));
                console.log(this.node);
                if (self.AllCorrectArray[i].indexOf(this.node) != -1) {
                    //console.log(self.LockArray);
                    if (self.main.LockArray.length == 0) {
                        console.log("赋值了");
                        self.main.LockArray = self.AllCorrectArray[i];
                    }
                    for (let j = 0; j < self.main.LockArray.length; j++) {
                        console.log("到底关没关啊");
                        // console.log(self.AllCorrectArray[i][j].getComponent("Drag"));
                        // self.AllCorrectArray[i][j].getComponent("Drag").destroy();
                        self.main.LockArray[j].off(cc.Node.EventType.TOUCH_START);
                        self.main.LockArray[j].off(cc.Node.EventType.TOUCH_MOVE);
                        self.main.LockArray[j].off(cc.Node.EventType.TOUCH_END);
                        self.main.LockArray[j].off(cc.Node.EventType.TOUCH_CANCEL);// getComponent("Drag").enabled;
                        // if (self.LockArray.indexOf(self.AllCorrectArray[i][j]) == -1) {
                        //    self.LockArray.push(self.AllCorrectArray[i][j]);
                        // }
                        console.log(self.AllCorrectArray);
                        console.log(self.LockArray);
                        //  self.LockArray.shift();
                        //  console.log(self.LockArray);
                        console.log(self.main.LockArray);
                        console.log(self.LockArray);
                        // console.log(self.LockArray);
                    }
                    break;
                }
            }
        }
        console.log(self.isLock);


    },
    JudgeIsHaveKernel(angele, target, numX, numY) {
        var self = this;
        if (target.length > 0) {
            console.log("有人");
            for (let i = 0; i < target.length; i++) {
                console.log(this.node);
                if (target[i].getComponent("Drag").name == (Number(this.name[0]) + numX) + "_" + (Number(this.name[2]) + numY)) {
                    console.log("对的人");
                    if (Math.floor(target[i].rotation % 360) == angele) {
                        console.log("又对了兄弟");
                        let isHaveArray = false;


                        let targetIn = false;
                        let targetAround = false;
                        for (let k = 0; k < self.AllCorrectArray.length; k++) {
                            for (let j = 0; j < self.AllCorrectArray[k].length; j++) {
                                if (self.AllCorrectArray[k][j] == this.node) {
                                    targetIn = true;
                                }
                                if (self.AllCorrectArray[k][j] == target[i]) {
                                    targetAround = true;
                                }
                            }
                        }
                        if (targetIn == false && targetAround == false) {
                            self.AllCorrectArray.push([this.node, target[i]]);
                            self.correctMusic.play();
                        }
                        else if (targetIn == false && targetAround == true) {
                            for (let k = 0; k < self.AllCorrectArray.length; k++) {
                                for (let j = 0; j < self.AllCorrectArray[k].length; j++) {
                                    if (self.AllCorrectArray[k][j] == target[i]) {
                                        self.AllCorrectArray[k].push(this.node);
                                        self.correctMusic.play();

                                        break;
                                    }
                                }
                            }
                        }
                        else if (targetIn == true && targetAround == false) {
                            for (let k = 0; k < self.AllCorrectArray.length; k++) {
                                for (let j = 0; j < self.AllCorrectArray[k].length; j++) {
                                    if (self.AllCorrectArray[k][j] == this.node) {
                                        self.AllCorrectArray[k].push(target[i]);
                                        self.correctMusic.play();
                                        break;
                                    }
                                }
                            }
                        }
                        else if (targetIn == true && targetAround == true) {
                            console.log("全有小兄弟");
                            let arrayIndex = 0;
                            let deltteIndex = -1;
                            for (let k = 0; k < self.AllCorrectArray.length; k++) {
                                for (let j = 0; j < self.AllCorrectArray[k].length; j++) {
                                    if (self.AllCorrectArray[k][j] == target[i]) {
                                        arrayIndex = k;
                                    }
                                }
                            }
                            console.log(arrayIndex);
                            let complete = false;

                            for (let k = 0; k < self.AllCorrectArray.length; k++) {
                                console.log("awwaa,," + this.node.name);
                                if (k == arrayIndex) {
                                    continue;
                                }

                                for (let j = 0; j < self.AllCorrectArray[k].length; j++) {
                                    console.log("sdfvvvv,," + this.node.name);

                                    if (self.AllCorrectArray[k][j] == this.node) {

                                        for (let m = 0; m < self.AllCorrectArray[k].length; m++) {
                                            console.log("ssccbttt,," + this.node.name);
                                            if (self.AllCorrectArray[arrayIndex].indexOf(self.AllCorrectArray[k][m]) == -1) {
                                                self.AllCorrectArray[arrayIndex].push(self.AllCorrectArray[k][m]);
                                                self.correctMusic.play();
                                                console.log(self.AllCorrectArray[arrayIndex]);
                                            }
                                        }
                                        complete = true;
                                        if (deltteIndex == -1) {
                                            deltteIndex = k;
                                        }
                                        setTimeout(() => {
                                            self.AllCorrectArray[deltteIndex].splice(0, self.AllCorrectArray[deltteIndex].length);
                                        }, 100);
                                        break;
                                    }
                                }
                                if (complete) {
                                    break;
                                }
                            }
                        }
                        console.log(self.AllCorrectArray);
                    }
                    break;
                }
            }
        }
    },
    JudgeIsHave(BGW, BGH) {
        console.log(this.node.name + "判断");
        var self = this;
        if (self.BGisHave[BGW - 1][BGH - 1].indexOf(this.node) == -1) {
            self.BGisHave[BGW - 1][BGH - 1].push(this.node);
            console.log("push了");
            console.log(self.BGisHave);
        }
        console.log(BGW + BGH);
        let rot = this.node.rotation % 360;
        if (BGW != self.height) {
            //上面那块有东西
            self.JudgeIsHaveKernel(rot, self.BGisHave[BGW][BGH - 1], Math.round(Math.cos((360 - rot) * Math.PI / 180)), Math.round(Math.sin((360 - rot) * Math.PI / 180)));
        }
        if (BGH != 1) {
            //左面那块有东西
            self.JudgeIsHaveKernel(rot, self.BGisHave[BGW - 1][BGH - 2], Math.round(Math.sin((180 + rot) * Math.PI / 180)), Math.round(Math.cos((180 + rot) * Math.PI / 180)));
        }
        if (BGH != self.width) {
            //右面那块有东西
            self.JudgeIsHaveKernel(rot, self.BGisHave[BGW - 1][BGH], Math.round(Math.sin(rot * Math.PI / 180)), Math.round(Math.cos(rot * Math.PI / 180)));
        }
        if (BGW != 1) {
            //下面那块有东西
            self.JudgeIsHaveKernel(rot, self.BGisHave[BGW - 2][BGH - 1], Math.round(Math.cos((180 - rot) * Math.PI / 180)), Math.round(Math.sin((180 - rot) * Math.PI / 180)));
        }
    },
    update(dt) {
    },
});
